package org.chatboleh.tools;

import java.util.List;

import org.chatboleh.bean.User;
import org.chatboleh.exception.EDMException;

public class UserFactory extends BaseFactory {

	private static UserFactory userfactory = null;

	/**
	 * This returns the singleton instance
	 */
	public static UserFactory getInstance() {
		if (userfactory == null) {
			userfactory = new UserFactory();
		}
		return (userfactory);
	}

	public User createUser(String username, String password, String email) {
		return createUser(username, password, email, true);
	}

	public User createUser(String username, String password, String email,
			boolean disabled) {
		User user = new User();
		user.setUsername(username);
		user.setPassword(password);
		user.setEmail(email);
		user.setDisabled(disabled);
		try {
			user.save();
		} catch (EDMException e) {
			logger.error(e);
		}
		return user;
	}

	public List<User> getUserList(String criteria) {
		try {
			return new User().getList(criteria);
		} catch (EDMException e) {
			logger.error(e);
		}
		return null;
	}

}
